package com.syedu.day13.homework2;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Scanner;

/**
 * 输入年月,然后打印如下格式的日历
 */
public class PrintCalendar {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请您输入年份: ");
        int year = scanner.nextInt();
        System.out.println("请您输入月份: ");
        int month = scanner.nextInt();

        LocalDate date = LocalDate.of(year, month, 1);
        int weekday = date.getDayOfWeek().getValue();//星期
        int day = date.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();//月总天数

        System.out.println("---" + year + "年" + month + "月的日历表---");
        System.out.println("一\t二\t三\t四\t五\t六\t日");
        //打印空格
        for (int i = 1; i < weekday; i++) {
            System.out.print("\t");
        }
        //输出日历
        for (int i = 1; i <= day; i++) {
            System.out.print(i + "\t");
            //判断换行
            if ((weekday + i - 1) % 7 == 0) {
                System.out.println();
            }
        }
    }
}